package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.Ship;

public class GetX extends EntityExpression {

	public GetX(E e){
		super(e);
	}
	
	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject){
		this.map =map;
		try{
			if(getExpression().getContent(map, givenCollisionObject) instanceof CollisionObject){
		CollisionObject collisionObject = (CollisionObject) getExpression().getContent(map, givenCollisionObject);
		return collisionObject.getXCoordinate();
		}
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}
		catch(NullPointerException exc){
			if(givenCollisionObject.isShip()){
				Ship ship = (Ship)givenCollisionObject;
				ship.getProgram().setMistake();
			}
			System.out.println("There is something wrong with you're program, please re-enter a new one.");
			return null;
		}
	}
	
//	public String toString(){
//		String content = getContent(map, collisionObject) + "";
//		return content;
//	}
	Map<String,E> map;
}